var CountryList = function() {

	$("#conutryName").bind('click', function(){
		
		if(browsepage == true || browsepage=="true"){
			return false;
		}
		
		var myts = new Date();
		jQuery.ajax( {
			type : "GET",
			async : false,
			url : ebvp_context + "/register/qryCountryList?myts=" + myts,
			dataType : "text",
			success : function(result) {
				var zArr = eval(result);
				for(var loop=0; loop<zArr.length; loop++){
					var zGroup = zArr[loop];
					
					if(zGroup.zName == "YZ"){
						$("#YZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#YZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
					
					if(zGroup.zName == "OZ"){
						$("#OZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#OZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
					
					if(zGroup.zName == "BMZ"){
						$("#BMZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#BMZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
					
					if(zGroup.zName == "FZ"){
						$("#FZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#FZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
							
						}
					}
					
					if(zGroup.zName == "NMZ"){
						$("#NMZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#NMZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
					
					if(zGroup.zName == "DYZ"){
						$("#DYZ").next("div").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#DYZ").next("div").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
					
					if(zGroup.zName == "ALL"){
						$("#ALL").empty();
						var cArr = zGroup.countryList;
						for(var l=0; l<cArr.length; l++){
							var cObj = cArr[l];
							$("#ALL").append("<a id=\""+cObj.pk_country+"\" href=\"#\" >"+cObj.name+"</a>");
						}
					}
				}
			}
		})
		
		var position = $("#conutryName").offset();
		$("#countryPicker").slideDown("normal");
		$("#countryPicker").offset(position);
		
	});

	var tabsFunction = function(){
		$("#countryPickerTabs a").bind('click', function() {
			$("#countryPickerTabs a").removeClass("active");
			var id = $(this).attr("href").split("#")[1];
			$(".country_list").hide();
			$(this).addClass("active");
			$("#" + id).removeClass("hidden").show();
			return false;
		});
	} 
	
	this.init = function(){
		
		tabsFunction();
		
		$("body").delegate(".country_list a", 'click', function(){
			$("#conutryName").val($(this).html()).trigger('keydown');
			$("#pk_country").val($(this).attr("id")).trigger('keydown');
			$("#countryPicker").slideUp("normal");
			
			if($("#conutryName").val() != null && $("#conutryName").val()!=""){
				$("#conutryName").UITipInside();
				$("#conutryName").removeClass("color_red").addClass("color_black");
			}
			
			return false;
		});
	}
}

$(function() {
	var countryListInstance = new CountryList();
	countryListInstance.init();
});
